Recalculate Counter Cache of 120k Records [Rails / ActiveRecord]

Posted by Sebastian on Stack Overflow See other posts from Stack Overflow or by Sebastian
Published on 2010-05-06T17:07:16Z Indexed on 2010/05/06 17:38 UTC
Read the original article Hit count: 283

Filed under:
|
|

The following situation:

I have a poi model, which has many pictures (1:n). I want to recalculate the counter_cache column, because the values are inconsistent.

I've tried to iterate within ruby over each record, but this takes much too long and quits sometimes with some "segmentation fault" bugs.

So i wonder, if its possible to do this with a raw sql query?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about ruby-on-rails